﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;//
using System.Web;
using System.Net;
using System.IO;
using System.Data.OleDb;

namespace AllData
{
    public class DataLink
    {
        SqlConnection conn;
        string strConn;
        public void open()
        {
            strConn = "Data Source=47.98.232.7;Initial Catalog=by_zhsq;User Id=sa;Password=012401403swq";
            conn = new SqlConnection(strConn);
            conn.Open();
        }
        public DataSet getData(string strCmd)
        {

            open();  //打开数据库
            SqlDataAdapter da = new SqlDataAdapter(strCmd, conn);
            DataSet ds = new DataSet();  //填充容器
            da.Fill(ds);
            conn.Close();
            return (ds);
        }
        public void SetUpdate(string Cmd)
        {
            open();  //打开数据库
            SqlCommand cmd = new SqlCommand(Cmd, conn);
            cmd.ExecuteNonQuery();
            conn.Close();
        }
        /// 返回JSon数据
        /// </summary>
        /// <param name="JSONData">要处理的JSON数据</param>
        /// <param name="Url">要提交的URL</param>
        /// <returns>返回的JSON处理字符串</returns>
        public string GetResponseData(string JSONData, string Url)
        {
            byte[] bytes = Encoding.UTF8.GetBytes(JSONData);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
            request.Method = "POST";
            request.ContentLength = bytes.Length;
            request.ContentType = "json";
            Stream reqstream = request.GetRequestStream();
            reqstream.Write(bytes, 0, bytes.Length);
            //声明一个HttpWebRequest请求
            request.Timeout = 90000;
            //设置连接超时时间
            request.Headers.Set("Pragma", "no-cache");
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream streamReceive = response.GetResponseStream();
            Encoding encoding = Encoding.UTF8;
            StreamReader streamReader = new StreamReader(streamReceive, encoding);
            string strResult = streamReader.ReadToEnd();
            streamReceive.Dispose();
            streamReader.Dispose();
            return strResult;
        }

        public class WXApi
        {
            public string access_token { set; get; }
        }
    }
}